package app.modules.security.util.conversion;

import app.modules.common.annotation.ConvertFrom;
import app.modules.common.annotation.ConvertTo;
import app.modules.security.dto.web.role.WebRoleDTO;
import jasmine.framework.common.util.CollectionUtil;
import jasmine.framework.common.util.MapperUtil;
import jasmine.security.rbac.model.SecRole;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author mh.z
 */
public class RoleConvertUtil {

    @ConvertFrom(SecRole.class)
    @ConvertTo(WebRoleDTO.class)
    public static WebRoleDTO secRole2WebRoleDTO(SecRole secRole) {
        if (secRole == null) {
            return null;
        }

        return MapperUtil.mapTo(secRole, WebRoleDTO.class);
    }

    @ConvertFrom(SecRole.class)
    @ConvertTo(WebRoleDTO.class)
    public static List<WebRoleDTO> secRole2WebRoleDTO(Collection<SecRole> secRoles) {
        if (CollectionUtil.isEmpty(secRoles)) {
            return Collections.emptyList();
        }

        return MapperUtil.mapToList(secRoles, WebRoleDTO.class);
    }

}
